//
//  DockInterfaceView.m
//  标签菜单
//
//  Created by Burn on 2019/7/24.
//  Copyright © 2019 menksoft. All rights reserved.
//

#import "DockInterfaceView.h"
#import "DockTitleStyle.h"
#import "DockTitleView.h"
#import "DockView.h"

@interface DockInterfaceView ()<DockViewDelegate,DockTitleViewDelegate>

@property(strong,nonatomic) DockTitleView *titleView;
@property(strong,nonatomic) DockView *dockView;

@property(weak,nonatomic) UIViewController *parentVC;
@property(weak,nonatomic) NSArray *childVC;
@property(strong,nonatomic) DockTitleStyle *style;
@property(strong,nonatomic) NSArray *titles;

@end

@implementation DockInterfaceView

- (instancetype)initWithFrame:(CGRect)frame style:(DockTitleStyle *)style titles:(NSArray *)titles childVCs:(NSArray *)vcs parentVC:(UIViewController *)vc{
    
    if (self = [super initWithFrame:frame]) {
        self.parentVC = vc;
        self.titles = titles;
        self.style = style;
        self.childVC = vcs;
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews{
    
    CGRect titleFrame = CGRectMake(0, 0, self.bounds.size.width, self.style.titileHeight);
    self.titleView = [[DockTitleView alloc]initWith:self.titles frame:titleFrame style:self.style];
    [self addSubview:self.titleView];
    
    CGRect dockFrame = CGRectMake(0, self.style.titileHeight, self.bounds.size.width, self.bounds.size.height - self.style.titileHeight);
    self.dockView = [[DockView alloc]initWithFrame:dockFrame ChildControllers:self.childVC parentController:self.parentVC];
    [self addSubview:self.dockView];
    
    self.titleView.delegate = self;
    self.dockView.delegate = self;
}

#pragma mark - TitleViewDelagete
- (void)dockTitleClickWith:(NSInteger)oldIndex currentIndex:(NSInteger)currentIndex{
    [self.dockView setCurrentInde:currentIndex];
}

#pragma mark - DockViewMove
- (void)dockMoveWithProgress:(CGFloat)pro fromeIndex:(NSInteger)oldIndex destinationIndex:(NSInteger)newIndex{
    [self.titleView setTitleWithProgress:pro oldIndex:oldIndex newIndex:newIndex];
//    NSLog(@"%f----oldIndex = %ld----newIndex = %ld",pro,oldIndex,newIndex);
}

- (void)dockMoveEnd{
    
}

- (void)dealloc{
    NSLog(@"DockInterfaceViewDealloc");
}

@end
